﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business_Objects;
using ServicesComponent.Repositories;

public partial class QuanLyHocSinh_BaoAn : System.Web.UI.Page
{
    public int id = 1;
    private IBaoAnRepository _BaoAnRepository;
    private IClassRepository _ClassRepository;
    protected void Page_Load(object sender, EventArgs e)
    {
        id = id + 1;
        if (!IsPostBack)
        {
            if (Request.QueryString["Refresh"] != null)
            {
                _BaoAnRepository = FactoryServices.GetServicesBaoAn(_BaoAnRepository);
             //   Bind();
                return;
            }
            if (Request.QueryString["Page"] != null)
            {
                id = (int.Parse(Request.QueryString["Page"].ToString()) - 1) * 14 + 1;
            }

          //  GetDataRepeatEdit(Convert.ToDateTime(txtNgayDD.Text));
            GetDataRepeatEdit(Convert.ToDateTime("18/11/2013"));
        }
        _BaoAnRepository = FactoryServices.GetServicesBaoAn(_BaoAnRepository);
        _ClassRepository = FactoryServices.GetServicesClass(_ClassRepository);
        //Bind();
    }
    void GetDataRepeatEdit(DateTime ngayBaoAn)
    {
        _BaoAnRepository = FactoryServices.GetServicesBaoAn(_BaoAnRepository);
        rptA.DataSource = _BaoAnRepository.GetBaoAnBySchoolIdAndSchoolYearAndNgayBaoAn(Session["SchoolYearID"].ToString(),
                                                                     int.Parse(Session["SchoolID"].ToString()), ngayBaoAn);

        rptA.DataBind();

        Cpage.DataSource = _BaoAnRepository.GetBaoAnBySchoolIdAndSchoolYearAndNgayBaoAn(Session["SchoolYearID"].ToString(),
                                                                     int.Parse(Session["SchoolID"].ToString()), ngayBaoAn);
        Cpage.BindToControl = rptA;
        rptA.DataSource = Cpage.DataSourcePaged;
    }

    //void Bind()
    //{
    //    rptA.Dispose();
    //    // rptA.RenderControl("f");
    //    rptA.DataSource = null;
    //    //   rptA.BeginResetItemTemplate();
    //    //Truyền @ClassID="";
    //    rptA.DataSource = _BaoAnRepository.GetBaoAnBySchoolIdAndSchoolYear(Session["SchoolYearID"].ToString(), int.Parse(Session["SchoolID"].ToString()));
    //    // rptA.DataSource = _ClassRepository.GetClassPhanLopBySchoolIdAndSchoolYearID(Session["SchoolYearID"].ToString(), int.Parse(Session["SchoolID"].ToString()));
    //    rptA.DataBind();
    //    Cpage.DataSource = _BaoAnRepository.GetBaoAnBySchoolIdAndSchoolYear(Session["SchoolYearID"].ToString(), int.Parse(Session["SchoolID"].ToString()));
    //    // Cpage.DataSource = _ClassRepository.GetClassPhanLopBySchoolIdAndSchoolYearID(Session["SchoolYearID"].ToString(), int.Parse(Session["SchoolID"].ToString()));
    //    Cpage.BindToControl = rptA;
    //    rptA.DataSource = Cpage.DataSourcePaged;
    //    // drAddress.EndResetItemTemplate()

    //}

    public string GetTenLopById(string id)
    {
        _ClassRepository = FactoryServices.GetServicesClass(_ClassRepository);
        Class obj = _ClassRepository.Get(id);
        return obj.Name;
    }
    public string ConVertDate(DateTime startDate)
    {
        return startDate.ToShortDateString();
    }
    protected void txtNgayDD_TextChanged(object sender, EventArgs e)
    {
       GetDataRepeatEdit(Convert.ToDateTime(txtNgayDD.Text));
    }
    protected void btnHide_Click(object sender, EventArgs e)
    {
       GetDataRepeatEdit(Convert.ToDateTime(txtNgayDD.Text));
    }
    
}